package cn.jiahua.test19;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class Test1 {

    /**
     * 了解
     * @param args
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //有返回值的异步请求
        CompletableFuture<Integer> completableFuture =CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+"supply asyn");
             int i=10/0;
            return 1024;
        });

        int result=  completableFuture.whenComplete((t,u)->{
           System.out.println("正确的结果返回是："+ t);
            System.out.println("异常返回结果："+u);

        }).exceptionally((e)->{
            System.out.println(e.getMessage());
            return 500;
        }).get();

        System.out.println(
                result
        );




    }
}
